<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.ok{
			    color:green;
			}
			.error{
			    color:red;
			}
		</style>
	</head>
	<body>
		名字<input type="text" id="name" onblur="checkName()"/>
		<span  id="nameMsg">5-10位的字母、数字、下划线</span>
		<br/>
		
		邮箱<input type="text" id="email" onblur="checkEmail()"/>
		<span id="emailMsg">必须符合邮箱的格式</span>
		
		<script type="text/javascript">
			function checkName() {
				var name = document.getElementById('name').value;
				var nameMsgSpan = document.getElementById('nameMsg');
				var reg = /^\w{5,10}$/;
				if (reg.test(name)) {
					// class="ok"
					nameMsgSpan.className = 'ok';
				} else {
					nameMsgSpan.className = 'error';
				}
			}
			
			function checkEmail() {
				var email = document.getElementById('email').value;
				var emailMsgSpan = document.getElementById('emailMsg');
				// situ@gmail.com.cn
				var reg = /^\w+@(\w+\.)+\w+$/;
				if (reg.test(email)) {
					// class="ok"
					emailMsgSpan.className = 'ok';
				} else {
					emailMsgSpan.className = 'error';
				}
			}
		</script>
	</body>
</html>
